<?php
	session_start();

	if ($_SESSION["role"] != "admin")
	{
		header('Location: ../index.php');
		exit();
	}
	
	/**
	* @package admin
	* @desc This page is to view the list of reports that users have made.
	*/
	/**
	* @desc This include file will load the directory settings for the Smarty Templates
	*/
	require '../includes/smarty.inc';
	$smarty->assign('title', "Reports");
	$smarty->assign('user_id', $_SESSION["user_id"]);	
	$smarty->assign('last', $_SESSION["lastviewed"]);
	$smarty->assign('firstname', $_SESSION["firstname"]);
	$smarty->assign('role', $_SESSION["role"]);
	$smarty->assign('top5', $_SESSION["top5"]);	
	$smarty->assign('pathdepth', "../");
	$smarty->display('header.tpl');
	
	
	
	//get reports from database
	$query = "SELECT r.report_id as id, r.forwarded as forwarded, u.email as email, p.name as park, p.address as address, s.name as suburb FROM reports r, users u, suburbs s, parks p WHERE (r.user_id = u.user_id) AND (r.park_id = p.park_id) AND (p.suburb_id = s.suburb_id)";
	
	/**
	* @desc This include file connects to the database.
	*/
	require '../includes/connect.inc';
	
	//run query
	$result = mysql_query($query, $connection) or die("Could not load reports from database");
	

	$smarty->assign('admin', $_SESSION['firstname']);
	
	$count = mysql_num_rows($result);
	$smarty->assign('count', $count);
	$reports = array();
	while ($row = mysql_fetch_array($result))
	{
		$output = array('id' => $row['id'], 'park' => $row['park'], 'email' => $row['email'], 'address' => $row['address'], 'suburb' => $row['suburb'], 'forwarded' => $row['forwarded']);		
		$reports[] = $output;
	}
	$smarty->assign('reports', $reports);
	
	$smarty->display('admin/reports.tpl');
	
	//disconnect from db
	mysql_close($connection);
	
	//Footer
	$smarty->assign('pathdepth', "../");
	$smarty->display('footer.tpl');
	
	
?>